package BandB.Tool.GPhoneManager.TaskManager;

import java.util.ArrayList;

import BandB.Tool.GPhoneManager.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridAdapter extends BaseAdapter {

	private ArrayList<ApplicationInfo> infoList;
	private LayoutInflater inflater;

	public GridAdapter(Context c, ArrayList<ApplicationInfo> list) {
		infoList = list;
		inflater = LayoutInflater.from(c);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ApplicationInfo info = (ApplicationInfo) getItem(position);

		if (null == convertView) {
			convertView = inflater.inflate(R.layout.grid_process_item, null);
		}
		ImageView icon = (ImageView) convertView
				.findViewById(R.id.grid_pro_icon);
		TextView nameTextView = (TextView) convertView
				.findViewById(R.id.grid_pro_name);
		icon.setImageDrawable(info.icon);
		nameTextView.setText(info.title);
		return convertView;
	}

}
